package dawnland03.model.task;

/**
 * User: Petru Obreja (obrejap@yahoo.com)
 * Date: Jan 21, 2010
 * Time: 10:59:10 PM
 */
public enum TaskStatus {
    CREATED(10),
    INITIALISED(20),
    PREPARED(30),
    RUNNING(40),
    FINISHED(50);

    private int level;

    private TaskStatus(int level) {
        this.level = level;
    }

    public TaskStatus getNextStatus() {
        switch (this) {
            case CREATED:
                return INITIALISED;
            case INITIALISED:
                return PREPARED;
            case PREPARED:
                return RUNNING;
            case RUNNING:
                return FINISHED;
            case FINISHED:
                throw new IllegalStateException(TaskStatus.FINISHED + " is the last status.");
            default:
                throw new IllegalStateException("Unknown state:" + this);
        }
    }

    public TaskStatus getBeforeStatus() {
        switch (this) {
            case CREATED:
                throw new IllegalStateException(TaskStatus.CREATED + " is the first status.");
            case INITIALISED:
                return CREATED;
            case PREPARED:
                return INITIALISED;
            case RUNNING:
                return PREPARED;
            case FINISHED:
                return RUNNING;
            default:
                throw new IllegalStateException("Unknown state:" + this);
        }
    }

    public static TaskStatus getFirstStatus(){
        return CREATED;
    }

    public static TaskStatus getLastStatus() {
        return FINISHED;
    }
}
